package com.qfedu.orderitem.service.Impl;
import com.qfedu.fmmall.entity.OrderItem;
import com.qfedu.fmmall.entity.ShoppingCartVo;
import com.qfedu.orderitem.dao.OrderItemAddMapper;
import com.qfedu.orderitem.service.OredrItemAddService;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Random;

public class OrderItemAddServiceImpl implements  OredrItemAddService{

    @Autowired
    private OrderItemAddMapper orderItemAddMapper;

    @Override
    public int save(List<ShoppingCartVo> list, String orderId) {
        int j = 1;
        for (ShoppingCartVo sc:list) {
            int cnum = Integer.parseInt(sc.getCartNum());
            String itemId = System.currentTimeMillis()+""+(new Random().nextInt(89999)+10000);
            OrderItem orderItem = new OrderItem(itemId,orderId,sc.getProductId(),sc.getProductName(),
                    sc.getProductImg(),sc.getSkuId(),sc.getSkuName(),new BigDecimal(sc.getSellPrice())
                    ,cnum,new BigDecimal(sc.getOriginalPrice()*cnum),new Date(),new Date(),0);
            int i = orderItemAddMapper.insert(orderItem);
            j*=i;
        }

        return j;
    }
}
